Skip to content

Fix: Helm post-delete hook#7678

Open
Varshar21-07 wants to merge 2 commits into
karmada-io:masterfrom
Varshar21-07:issue-7618-helm-post-delete
Open

Fix: Helm post-delete hook#7678
Varshar21-07 wants to merge 2 commits into
karmada-io:masterfrom
Varshar21-07:issue-7618-helm-post-delete

Conversation

@Varshar21-07

Copy link
Copy Markdown

What type of PR is this?
/kind bug

What this PR does / why we need it:
This PR resolves a critical issue in the Helm chart where uninstalling the chart via the post-delete hook accidentally deletes cluster-scoped Namespace objects (like karmada-system and karmada-cluster) on the host cluster.

During uninstallation, the post-delete-job.yaml hook ran kubectl delete -f /opt/static-resources/ against the host cluster. Because system-namespace.yaml is located in that directory, the host cluster was instructed to delete those namespaces, cascading and destroying all resources inside them.

This PR replaces the broad kubectl delete -f command with a shell loop that explicitly ignores system-namespace.yaml during the cleanup process, preserving the namespaces on the host cluster while maintaining the cleanup logic for all other static resources.

Which issue(s) this PR fixes:
Fixes #7618

Special notes for your reviewer:
This has been manually verified by installing the Helm chart with --set systemNamespace=karmada-test-system onto a host cluster, and confirming that karmada-test-system is no longer deleted from the host cluster upon running helm uninstall.

Does this PR introduce a user-facing change?:

`Helm chart`: Fixed an issue where the `post-delete` hook accidentally deleted the `karmada-system` namespace 
on the host cluster during uninstallation.

Copilot AI review requested due to automatic review settings June 28, 2026 11:04
@gemini-code-assist

Copy link
Copy Markdown

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses a critical bug in the Helm chart's uninstallation process where the post-delete hook was inadvertently removing cluster-scoped namespaces. By modifying the cleanup script to filter out specific configuration files, the change ensures that essential system namespaces remain intact on the host cluster while maintaining proper resource cleanup for other components.

Highlights

  • Helm post-delete hook logic: Replaced the bulk deletion command in the post-delete hook with a shell loop to iterate through static resources.
  • Namespace preservation: Added a conditional check to explicitly ignore 'system-namespace.yaml' during the cleanup process, preventing accidental deletion of critical host namespaces.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@karmada-bot

Copy link
Copy Markdown
Contributor

Welcome @Varshar21-07! It looks like this is your first PR to karmada-io/karmada 🎉

@karmada-bot karmada-bot added the size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. label Jun 28, 2026
@karmada-bot

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign poor12 for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@karmada-bot karmada-bot requested review from calvin0327 and jrkeen June 28, 2026 11:05

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request modifies the post-delete job template in the Karmada Helm chart to skip deleting the system-namespace.yaml file from /opt/static-resources/ during cleanup. The review feedback suggests optimizing the bash loop by using built-in parameter expansion (${file##*/}) instead of spawning a subshell with basename, and adding an existence check [[ -e "$file" ]] to prevent errors if the glob pattern matches nothing.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment on lines +50 to +54
for file in /opt/static-resources/*; do
if [ "$(basename "$file")" != "system-namespace.yaml" ]; then
kubectl delete -f "$file" --ignore-not-found=true -R || true
fi
done

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Using $(basename "$file") inside a loop spawns a subshell and executes an external binary (basename) for every file in the directory. Since the script is executed using bash, we can use bash's built-in parameter expansion ${file##*/} instead. This is more efficient, avoids spawning external processes, and is more robust as it doesn't rely on the availability of the basename command in the container image.

Additionally, we can add a check [[ -e "$file" ]] to ensure the file exists before attempting to delete it, preventing errors if the glob pattern does not match any files.

              for file in /opt/static-resources/*; do
                if [[ -e "$file" && "${file##*/}" != "system-namespace.yaml" ]]; then
                  kubectl delete -f "$file" --ignore-not-found=true -R || true
                fi
              done

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a Helm post-delete hook behavior in the Karmada chart that could delete cluster-scoped Namespace objects on the host cluster during helm uninstall, by excluding system-namespace.yaml from the host-side static resource cleanup.

Changes:

  • Replaced kubectl delete -f /opt/static-resources/ ... -R with a loop that deletes each static resource file individually.
  • Explicitly skips system-namespace.yaml so host cluster namespaces like karmada-system / karmada-cluster are not deleted during uninstall.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@codecov-commenter

codecov-commenter commented Jun 28, 2026

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 42.06%. Comparing base (56d5d87) to head (7df1175).
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #7678      +/-   ##
==========================================
- Coverage   42.06%   42.06%   -0.01%     
==========================================
  Files         879      879              
  Lines       54831    54831              
==========================================
- Hits        23063    23062       -1     
  Misses      30023    30023              
- Partials     1745     1746       +1     
Flag Coverage Δ
unittests 42.06% <ø> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Signed-off-by: Varsha <varsha@Varshas-MacBook-Pro.local>
@Varshar21-07 Varshar21-07 force-pushed the issue-7618-helm-post-delete branch from 31fee00 to 015e8f8 Compare June 28, 2026 12:23
Signed-off-by: Varsha <varsha@Varshas-MacBook-Pro.local>
@Varshar21-07

Copy link
Copy Markdown
Author

Hi @RainbowMango @XiShanYongYe-Chang @jrkeen, I've submitted this fix. Please review this and let me know if any changes needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/XS Denotes a PR that changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Helm post-delete hook deletes systemNamespace and karmada-cluster on the host cluster, but they only get created in the karmada-apiserver

4 participants